<!-- 蓝色简洁登录页面 -->
<template>
  <view class="t-login">
    <!-- 标题 -->
    <view class="t-b">{{ title }}</view>
    <!-- 页面装饰图片 -->
    <image :showLoading="true" src="@/static/u98.svg"></image>
    <!-- 页面间隔    -->
    <view class="t-g"/>
    <form class="cl">
      <view class="t-a">
        <input type="number" name="phone" placeholder="请输入注册手机号" maxlength="11" v-model="phone"/>
      </view>
      <view class="t-a">
        <input type="password" name="code" maxlength="12" placeholder="请输入密码" v-model="password"/>
      </view>
      <button @tap="login()">登 录</button>
      <text class="t-p">忘记密码？
        <navigator open-type="navigate" url="/pages/auth/findPassword">立即找回</navigator>
      </text>
    </form>

  </view>
</template>
<script>
import userApi from '@/api/user'
import mineApi from "@/api/mine";
import passData from '@/api/requstUtil'
import {aesEncrypt, kk} from '@/common/js/crypto'

export default {

  data() {
    return {
      title: '登录开赢平台', //填写logo或者app名称，也可以用：欢迎回来，看您需求
      phone: '', //手机号码
      password: '' //密码
    };
  },
  onLoad() {
  },
  methods: {
    //当前登录按钮操作
    login() {
      if (this.checkParam()) {
        let encrypt = aesEncrypt(this.phone + this.password, kk);
        let param = {
          password: encrypt,
          tenantId: 'gysk',
          phone: this.phone,
        }
        userApi.login(param).then(res => {
          let data = passData(res);
          console.log("userApi.doLogin", data)
          if (data) {
            uni.showToast({title: '登录成功！', icon: 'none'});
            uni.setStorageSync('token', data.token);
            uni.setStorageSync('realName', data.realName);
            uni.setStorageSync('phone', data.phone);
            uni.navigateTo({url: '/pages/index/index'});
          }
        });
      }
      this.getMineData()

      //....此处省略，这里需要调用后台验证一下验证码是否正确，根据您的需求来
    },
      // 获取个人信息
      async getMineData() {
      try {
        const res = await mineApi.postQueryInfoData();
        let data = passData(res);
        if (data) {
          uni.setStorageSync('residentCity', data.residentCity);
          uni.setStorageSync('userId', data.userId);
        }
      } catch (e) {
        console.log(e);
      }
    },
    checkParam() {
      if (!this.phone) {
        uni.showToast({title: '请输入手机号', icon: 'none'});
        return false;
      }
      if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(this.phone)) {
        uni.showToast({title: '请输入正确手机号', icon: 'none'});
        return false;
      }
      if (!this.password) {
        uni.showToast({title: '请输入密码', icon: 'none'});
        return false;
      }
      return true
    },
  }
};
</script>
<style>

.t-login {
  width: 600rpx;
  margin: 0 auto;
  font-size: 28rpx;
  color: #000;
}

.t-login button {
  font-size: 14px;
  background: rgb(240, 95, 93);
  color: #fff;
  height: 42px;
  line-height: 45px;
  border-radius: 9px;
  box-shadow: 0 5px 7px 0 rgba(86, 119, 252, 0.2);
  width: 55%;
}

.t-login input {
  padding: 0 10px 0 21px;
  height: 46px;
  line-height: 46px;
  margin-bottom: 26px;
  background: #f8f7fc;
  border-bottom: 1px solid #e9e9e9;
  font-size: 15px;
  border-radius: 5px;
}

.t-login .t-a {
  position: relative;
}

.t-login .t-a image {
  width: 40rpx;
  height: 40rpx;
  position: absolute;
  left: 40rpx;
  top: 28rpx;
  border-right: 2rpx solid #dedede;
  padding-right: 20rpx;
}

.t-login .t-b {
  font-size: 18px;
  color: #000;
  padding: 35px 0 30px 0;
  font-weight: bold;
  text-align: center;
}


.t-login .t-d {
  text-align: center;
  color: #999;
  margin: 80rpx 0;
}

.t-login .t-p {
  text-align: center;
  display: block;
  margin: 16px auto auto auto;
  position: relative;
  font-size: 15px;
  color: #cccccc;
}

.t-p uni-navigator {
  display: contents;
  color: rgb(240, 95, 93);
}


.t-g {
  padding-top: 30px;
}

.t-login .t-f text {
  margin-left: 20rpx;
  color: #aaaaaa;
  font-size: 27rpx;
}

.t-login .uni-input-placeholder {
  color: #000;
}

.cl {
  zoom: 1;
}

.cl:after {
  clear: both;
  display: block;
  visibility: hidden;
  height: 0;
  content: '\20';
}

.t-login .uni-input-placeholder {
  color: #cccccc;
  font-size: 16px;
}
</style>
